<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="搜索工序任务单号/物料名称" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel">
					<!-- <el-button type="primary" @click="add" v-auth="'spare.add'">新增</el-button>
					<el-button type="primary" @click="add" v-auth="'spare.add'">报工</el-button>
					<el-button type="primary" @click="batch_show" v-auth="'spare.add'" :disabled="selection.length !== 1">查看</el-button>
					<el-button type="primary" :disabled="selection.length !== 1" @click="batch_edit" v-auth="'spare.edit'">修改</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'spare.deleteAll'">删除</el-button> -->
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column fixed="left" type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column label="工序编码" prop="work.work_code" align="center" width="110"></el-table-column>
					<el-table-column label="工序名称" prop="work.work_name" align="center" width="100"></el-table-column>
					<el-table-column label="受否委外" prop="work.is_out" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work.is_out == 1 ? 'success' : 'danger'">{{scope.row.work.is_out == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="委外供应商" prop="apply_name" align="center" width="100"></el-table-column>
                    <el-table-column label="物料编码" prop="product.goods_code" align="center" width="100"></el-table-column>
					<el-table-column label="物料名称" prop="product.goods_name" align="center" width="100"></el-table-column>
					<el-table-column label="物料类别" prop="product.cate_name" align="center"></el-table-column>
					<el-table-column label="物料规格" prop="product.goods_spec" align="center"></el-table-column>
					<el-table-column label="辅助属性" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="单位" prop="product.unit_name" align="center"></el-table-column>
					<el-table-column label="生产人员" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="车间" prop="customAddress" align="center"></el-table-column>
					<!-- <el-table-column label="设备" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="良品数" prop="customAddress" align="center">
                        <template #default="scope">
                            {{scope.row.work_number - scope.row.rejects_num}}
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="不良项" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="不良品数" prop="rejects_num" align="center"></el-table-column>
					<el-table-column label="报工数" prop="work_number" align="center"></el-table-column>
					<el-table-column label="开始时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="结束时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="报工时长（时）" prop="customAddress" align="center" width="110"></el-table-column>
					<el-table-column label="报工时长（分）" prop="customAddress" align="center" width="110"></el-table-column>
					<!-- <el-table-column label="标准效率" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="实际效率" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="达标率" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="计价方式" prop="customAddress" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.valuation_type == 0 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.valuation_type == 0 ?'计时':'计件'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="工资单价" prop="work.labor_piece" align="center"></el-table-column>
					<el-table-column label="预计工资" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="报工来源" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="已生成工资或费用" prop="customAddress" align="center" width="130"></el-table-column>
					<el-table-column label="需要校验" prop="work.is_quality" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.is_quality == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.is_quality == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="全检" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="抽检" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="检验方式" prop="customAddress" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.quaqty_type == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.quaqty_type == 1 ?'全检':'抽检'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="抽检比例（%）" prop="work.quaqty_rate" align="center" width="120"></el-table-column>
					<el-table-column label="是否生成报检单" prop="customAddress" align="center" width="120"></el-table-column>
					<el-table-column label="合格数量" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="不合格数量" prop="customAddress" align="center" width="100"></el-table-column>
					<el-table-column label="单据编号" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="创建人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="修改人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="修改时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核人" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核时间" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核日期" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="审核状态" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="备注" prop="remark" align="center" width="120"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="100">
                    <template #default="scope">
                        <el-button-group>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                <template #reference>
                                    <el-button text type="danger" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<!-- <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog> -->
</template>

<script>
// import saveDialog from "./save.vue";
export default {
	name: 'user',
	components: {
		// saveDialog
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.production.report.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
		}
	},
	watch: {

	},
	mounted() {

	},
	methods: {
		/**报工*/
		table_work() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
		/**查看点击*/
		batch_show() {
			this.$router.push({
				path: '/process/addWork',
			});
		},
		//添加
		add() {
			this.$router.push({
				path: '/process/addWork',
			});
		},
		//编辑
		table_edit() {
			this.$router.push({
				path: '/process/addWork',
			});
		},
		/**双击事件*/
		dblclick(row) {
			this.table_show(row)
		},
		//查看
		table_show(row) {
			let form = row
			form.zhuangtai = 'show'
			this.$router.push({
				path: '/bom/addBom',
				query: form
			});
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.production.report.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
			this.printArr = ''
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
